using Microsoft.AspNetCore.Mvc;
using Simple.Contracts.Contracts;
using Simple.Contracts.Models;
using Simple.Contracts.Models.Common;
using Simple.WebAi.Authorizes;
using System.ComponentModel.DataAnnotations;
using System.Threading.Tasks;

namespace Simple.WebAi.Controllers
{
    /// <summary>
    /// 照护计划模板控制器
    /// </summary>
    [Route("api/care-plan-template")]
    [ApiController]
    public class CarePlanTemplateController : ControllerBase
    {
        private readonly ICarePlanTemplateService _carePlanTemplateService;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="carePlanTemplateService">照护计划模板服务</param>
        public CarePlanTemplateController(ICarePlanTemplateService carePlanTemplateService)
        {
            _carePlanTemplateService = carePlanTemplateService;
        }

        /// <summary>
        /// 保存照护计划模板
        /// </summary>
        /// <param name="input">保存参数</param>
        /// <returns>模板Id</returns>
        [HttpPost("save")]
        [AccountAuthorize]
        public async Task<Result<long>> SaveCarePlanTemplateAsync(SaveCarePlanTemplateInput input)
        {
            return await _carePlanTemplateService.SaveCarePlanTemplateAsync(input);
        }

        /// <summary>
        /// 删除照护计划模板
        /// </summary>
        /// <param name="id">模板Id</param>
        /// <returns>删除结果</returns>
        [HttpPost("delete")]
        [AccountAuthorize]
        public async Task<Result<bool>> DeleteCarePlanTemplateAsync([FromQuery][Required] long id)
        {
            return await _carePlanTemplateService.DeleteCarePlanTemplateAsync(id);
        }

        /// <summary>
        /// 获取照护计划模板列表
        /// </summary>
        /// <returns>模板列表</returns>
        [HttpGet("list")]
        [AccountAuthorize]
        public async Task<Result<List<CarePlanTemplateDto>>> GetCarePlanTemplateList()
        {
            return await _carePlanTemplateService.GetCarePlanTemplateListAsync();
        }

        /// <summary>
        /// 获取照护计划模板详情
        /// </summary>
        /// <param name="id">模板Id</param>
        /// <returns>模板详情</returns>
        [HttpGet("detail/{id}")]
        [AccountAuthorize]
        public async Task<Result<CarePlanTemplateDto?>> GetCarePlanTemplateDetail(long id)
        {
            return await _carePlanTemplateService.GetCarePlanTemplateDetailAsync(id);
        }

        /// <summary>
        /// 复制照护计划模板
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost("copy")]
        [AccountAuthorize]
        public async Task<Result<long>> Copy(CopyCarePlanTemplateInput input)
        {
            return await _carePlanTemplateService.CopyCarePlanTemplateAsync(input);
        }
    }
}